package org.ala.tiktools_clickhouse_generator.generator.dao;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.ala.tiktools_clickhouse_generator.config.ConfigInfo;
import org.ala.tiktools_clickhouse_generator.generator.AbstractCreator;
import org.ala.tiktools_clickhouse_generator.generator.entity.EntityInfo;
import org.ala.tiktools_clickhouse_generator.generator.query.QueryInfo;
import org.ala.tiktools_clickhouse_generator.table.TableInfo;
import org.ala.tiktools_clickhouse_generator.tools.FileTools;

import freemarker.template.TemplateException;

/**
 *
 *	@author ala
 *	@date 2025年6月9日
 */
public class DaoCreator extends AbstractCreator {

	
	public DaoInfo create(ConfigInfo c, TableInfo ti, EntityInfo ei, QueryInfo qi) throws IOException, TemplateException {
		Map<String, Object> dataMeta = new HashMap<>();
        DaoInfo d = new DaoInfo(c.getPart().getOut().getDao(), ti, c.getPart().getAuthor(), ei, qi);
        dataMeta.put("d", d);
        
        String out = c.getPart().getOut().getDao().getPkg();
        out = this.getOutRootPath() + out.replaceAll("\\.", "/");
        FileTools.existsAndMakeDirs(out);
        out = out + "/" + d.getClassName() + ".java";

        output("Dao.ftl", dataMeta, out);

        System.out.println("生成Dao类. path:" + out);
        return d;
	}
}
